package com.blog.cloud.auth.oauth.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;

import java.util.Arrays;

@Getter
@RequiredArgsConstructor
public enum AuthUserGender {
    MALE("1", "男"),
    FEMALE("0", "女"),
    UNKNOWN("-1", "未知");

    private final String code;
    private final String desc;

    public static AuthUserGender getRealGender(String originalGender) {
        if (null != originalGender && !UNKNOWN.getCode().equals(originalGender)) {
            String[] males = new String[]{"m", "男", "1", "male"};
            return Arrays.asList(males).contains(originalGender.toLowerCase()) ? MALE : FEMALE;
        } else {
            return UNKNOWN;
        }
    }

    public static AuthUserGender getWechatRealGender(String originalGender) {
        return !StringUtils.isEmpty(originalGender) && !"0".equals(originalGender) ? getRealGender(originalGender) : UNKNOWN;
    }
}
